<template>
  <div class="student-info-container">
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <span>个人信息</span>
        </div>
      </template>
      <el-form :model="teacherInfo" label-width="120px" class="info-form">
        <el-form-item label="工号">
          <el-input v-model="teacherInfo.teacher_number" disabled></el-input>
        </el-form-item>
        <el-form-item label="姓名">
          <el-input v-model="teacherInfo.teacher_name"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">更新信息</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { getTeacherInfoAPI, updateTeacherInfoAPI } from '@/api/teacher/info'

const teacherInfo = ref({
  teacher_id: null,
  teacher_number: '',
  teacher_name: ''
})

const getTeacherInfo = async () => {
  const data = await getTeacherInfoAPI()
  teacherInfo.value = data
}

const onSubmit = async () => {
  await updateTeacherInfoAPI({ teacher_name: teacherInfo.value.teacher_name })
  await getTeacherInfo()
}

onMounted(() => {
  getTeacherInfo()
})
</script>

<style scoped>
.student-info-container {
  padding: 20px;
}
.box-card { width: 50%; margin: 0 auto; }
.card-header {
  text-align: center;
  font-size: 20px;
  font-weight: bold;
}
.info-form {
  margin-top: 20px;
}
</style>
